#pragma once

#include <string>
#include <iostream>
#include <vector>
#include "db_handler.h"

// 定义用户角色枚举
enum Role {
    CONSUMER,
    MERCHANT,
    DELIVERY_PERSON
};

// 用户类
class User {
public:
    User(int user_id, std::string phone, std::string password, Role role_id, std::string nickname = "")
        : user_id(user_id), phone(phone), password(password), role_id(role_id), nickname(nickname) {}

    int getUserID() const { return user_id; }
    std::string getPhone() const { return phone; }
    std::string getPassword() const { return password; }
    Role getRoleID() const { return role_id; }
    std::string getNickname() const { return nickname; }

    void setNickname(const std::string& nickname) { this->nickname = nickname; }
    void setPhone(const std::string& phone) { this->phone = phone; }
    void setPassword(const std::string& password) { this->password = password; }

private:
    int user_id;
    std::string phone;
    std::string password;
    Role role_id;
    std::string nickname;
};

namespace TakeAwayPlatform
{
    class LoginModule
    {
    public:
        LoginModule(DatabaseHandler& dbHandler);

        bool login(const std::string& phone, const std::string& password, User& user);
        bool registerUser(const std::string& phone, const std::string& password, const std::string& nickname);
        bool changePassword(const std::string& phone, const std::string& oldPassword, const std::string& newPassword);
        bool changePhone(const std::string& oldPhone, const std::string& newPhone);

    private:
        DatabaseHandler& dbHandler;
    };
}